/**
 * 单选SelectionModel
 *
 * @author xuzj
 */
CQCIS.grid.RadioSelectionModel = Ext.extend(Ext.grid.RowSelectionModel, {
    header: '<div class="x-grid3-row-radio">&#160;</div>',
    id: 'radio',
    fixed: true,
    dataIndex: '',
    sortable: false,
    width: 22,
    initEvents: function(){
        Ext.grid.CheckboxSelectionModel.superclass.initEvents.call(this);
        this.grid.on('render', function(){
            var view = this.grid.getView();
            view.mainBody.on('mousedown', this.onMouseDown, this);
            Ext.fly(view.innerHd).on('mousedown', this.onHdMouseDown, this);
        }, this);
    },
    onMouseDown: function(e, t){
        if (t.className == 'x-grid3-row-radio') {
            e.stopEvent();
            var row = e.getTarget('.x-grid3-row');
            if (row) {
                var index = row.rowIndex;
                if (this.isSelected(index)) {
                    this.deselectRow(index);
                } else {
                    this.selectRow(index, true);
                }
            }
        }
    },
    
    // private
    onHdMouseDown: function(e, t){
        if (t.className == 'x-grid3-hd-radio') {
            e.stopEvent();
            var hd = Ext.fly(t.parentNode);
            var isChecked = hd.hasClass('x-grid3-hd-radio-on');
            if (isChecked) {
                hd.removeClass('x-grid3-hd-radio-on');
                this.clearSelections();
            } else {
                hd.addClass('x-grid3-hd-radio-on');
                this.selectAll();
            }
        }
    },
    
    // private
    renderer: function(v, p, record){
        return '<div class="x-grid3-row-radio">&#160;</div>';
    }
});
